package com.silence.gmall.product.assembler;

import com.silence.gmall.product.domain.entity.SpuSaleAttr;
import com.silence.gmall.product.dto.SpuSaleAttrDto;
import org.mapstruct.*;

import java.util.List;

/**
 * @Author silence
 * @Date 2025-08-18 23:11
 * @Email 792245022@qq.com
 * @Version 1.0
 * @Description spu销售属性工厂
 */
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface SpuSaleAttrFactory {

    /**
     * 将 SpuSaleAttrDto 转换为 SpuSaleAttr
     *
     * @param source 源对象
     * @return 目标对象
     */
    @Named("spuSaleAttrDto2SpuSaleAttrWithContext")
    @Mapping(target = "spuId", expression = "java(spuId)")
    SpuSaleAttr spuSaleAttrDto2SpuSaleAttrWithContext(SpuSaleAttrDto source, @Context Long spuId);

    /**
     * 将 SpuSaleAttrDtoList 转换为 SpuSaleAttrList
     *
     * @param source 源对象
     * @return 目标对象
     */
    @Named("spuSaleAttrDtoList2SpuSaleAttrListWithContext")
    @IterableMapping(qualifiedByName = "spuSaleAttrDto2SpuSaleAttrWithContext")
    List<SpuSaleAttr> spuSaleAttrDtoList2SpuSaleAttrListWithContext(List<SpuSaleAttrDto> source, @Context Long spuId);
}
